<?xml version="1.0" encoding="windows-1251"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html lang="ru" xml:lang="ru">

<head>
  <meta http-equiv="Content-type" content="text/html; charset=windows-1251" />
  <title>Basis Test Suite - Data module</title>

  <style type="text/css">
    @import "style/default/style.css";

    /* */
    BODY
    {
      font-family: Georgia;
      font-size: small;
      _font-size: x-small;
    }
  </style>
  
  <script type="text/javascript"  src="../basis-all.js"></script>
  <script type="text/javascript"  src="test.js"></script>
  <script type="text/javascript"  src="common.js"></script>
</head>

<body>
  <script type="text/javascript">
    loadTest((function(){

      var Data = basis.data;

      var data = [
        { a: 11, b: 21, c: 31 },
        { a: 12, b: 22 },
        { a: 13, c: 33 },
        { b: 24, c: 34 },
        { a: 15 },
        { b: 26 },
        { c: 37 },
        { d: { a: 1, b: 2, c: 3 } }
      ];

      return [
        {
          name: 'Main frame',
          testcase: [
            {
              name: 'getter',
              testcase: [
                {
                  name: 'create from path',
                  test: function(){
                    var g = Function.getter('a');
                    this.is(11, g(data[0]));

                    var g = Function.getter('d.a');
                    this.is(1, g(data[data.length - 1]));
                  }
                },
                {
                  name: 'create from path with modificator',
                  test: function(){
                    var g = Function.getter('a', 'value: {0:.2}');
                    this.is("value: 11.00", g(data[0]));
                  }
                },
                {
                  name: 'create from function',
                  test: function(){
                    var g = Function.getter(function(object){ return object.a });
                    this.is(11, g(data[0]));

                    var g = Function.getter(function(object){ return object.a }, 'value: {0:.2}');
                    this.is("value: 11.00", g(data[0]));
                  }
                },
                {
                  name: 'create from getter',
                  test: function(){
                    var g = Function.getter('a');
                    var g2 = Function.getter(g);
                    this.is(g, g2);
                    this.is(11, g(data[0]));
                    this.is(11, g2(data[0]));

                    var g = Function.getter('a', '[{0}]');
                    var g2 = Function.getter(g);
                    this.is(true, g === g2);
                    this.is('[11]', g(data[0]));
                    this.is('[11]', g2(data[0]));

                    var g = Function.getter('a', '[{0}]');
                    var g2 = Function.getter(g, Function.$self);
                    this.is(false, g === g2);
                    this.is('[11]', g(data[0]));
                    this.is('[11]', g2(data[0]));

                    var g = Function.getter('a');
                    var g2 = Function.getter(g, '[{0}]');
                    this.is(false, g === g2);
                    this.is(11, g(data[0]));
                    this.is('[11]', g2(data[0]));

                    var g = Function.getter('a', '[{0}]');
                    var g2 = Function.getter(g, '{{0}}');
                    this.is(false, g === g2);
                    this.is('[11]', g(data[0]));
                    this.is('{[11]}', g2(data[0]));

                  }
                },
                {
                  name: 'use on array',
                  test: function(){
                    var g = Function.getter('a');
                    this.is("11,12,13,,15,,,", data.map(g).join(','));
                    this.is("11,12,13,15", data.map(g).filter(Function.$isNotNull).join(','));
                  }
                },
                {
                  name: 'comparation',
                  test: function(){
                    this.is(true, Function.getter('a') === Function.getter('a'));
                    this.is(true, Function.getter('a', '') !== Function.getter('a'));
                    this.is(true, Function.getter('a', false) === Function.getter('a'));
                    this.is(true, Function.getter('a', null) === Function.getter('a'));
                    this.is(true, Function.getter('a', undefined) === Function.getter('a'));

                    this.is(true, Function.getter(Function.$self) === Function.getter(Function.$self));
                    this.is(true, !Function.$self.getter);
                    this.is(true, !Function.$self.__extend__);

                    this.is(true, Function.getter(function(){ return 1 }) !== Function.getter(function(){ return 1 }));
                    this.is(true, Function.getter(function(){ return 1 }) !== Function.getter(function(){ return 1; }));
                    this.is(true, Function.getter(function(){ return 1 }) !== Function.getter(function(){ return 2 }));

                    this.is(true, Function.getter(function(){ return 1 }, Number) !== Function.getter(function(){ return 1 }, Number));
                    this.is(true, Function.getter(function(){ return 1 }, Number) !== Function.getter(function(){ return 1; }, Number));
                    this.is(true, Function.getter(function(){ return 1 }, Number) !== Function.getter(function(){ return 2 }, Number));

                    this.is(true, Function.getter(function(){ return 1 }, '') !== Function.getter(function(){ return 1 }, ''));
                    this.is(true, Function.getter(function(){ return 1 }, '') !== Function.getter(function(){ return 1; }, ''));
                    this.is(true, Function.getter(function(){ return 1 }, '') !== Function.getter(function(){ return 2 }, ''));

                    this.is(true, Function.getter(function(){ return 1 }, 'f') !== Function.getter(function(){ return 1 }, 'f'));
                    this.is(true, Function.getter(function(){ return 1 }, 'f') !== Function.getter(function(){ return 1; }, 'f'));
                    this.is(true, Function.getter(function(){ return 1 }, 'f') !== Function.getter(function(){ return 2 }, 'f'));

                    this.is(true, Function.getter(function(){ return 1 }, 'f') !== Function.getter(function(){ return 1 }, 'fs'));

                    this.is(true, Function.getter('a', Number) !== Function.getter('a'));
                    this.is(true, Function.getter('a', Number) === Function.getter('a', Number));
                    this.is(true, Function.getter(Function.$self, Number) === Function.getter(Function.$self, Number));
                    this.is(true, Function.getter(Function.$self, '') === Function.getter(Function.$self, ''));
                    this.is(true, Function.getter(Function.$self, 'asd') === Function.getter(Function.$self, 'asd'));
                    this.is(true, Function.getter(Function.$self, String) !== Function.getter(Function.$self, Number));

                    this.is(true, Function.getter('a', '') === Function.getter('a', ''));
                    this.is(true, Function.getter('a', '') !== Function.getter('a', 'f'));

                    this.is(true, Function.getter('a', Number) === Function.getter(Function.getter('a', Number)));
                    this.is(true, Function.getter('a', Number) !== Function.getter(Function.getter('a', Number), Number));

                    this.is(true, Function.getter('a', Function.getter('b', Number)) === Function.getter('a', Function.getter('b', Number)));
                    this.is(true, Function.getter('a', Function.getter('b', Number)) !== Function.getter('a', Function.getter('a', Number)));
                    this.is(true, Function.getter('a', Function.getter('b', Number)) !== Function.getter('a', Function.getter('b')));
                  }
                },
                {
                  name: 'non-cacheable comparation',
                  test: function(){
                    var object = {};
                    var array = {};

                    this.is(true, Function.getter('a', {}) !== Function.getter('a', {}));
                    this.is(true, Function.getter('a', object) !== Function.getter('a', object));

                    this.is(true, Function.getter('a', []) !== Function.getter('a', []));
                    this.is(true, Function.getter('a', array) !== Function.getter('a', array));
                  }
                },
                {
                  name: 'extensible',
                  test: function(){
                    var __extend__ = Function.getter('').__extend__;
                    var func = function(){};
                    var getter = Function.getter('random');

                    this.is(true, typeof __extend__ == 'function');

                    this.is(__extend__, Function.getter('a').__extend__);
                    this.is(__extend__, Function.getter('a', '').__extend__);
                    this.is(__extend__, Function.getter('a', function(){}).__extend__);
                    this.is(__extend__, Function.getter('a', {}).__extend__);
                    this.is(__extend__, Function.getter('a', []).__extend__);

                    this.is(__extend__, Function.getter(Function.$true).__extend__);
                    this.is(__extend__, Function.getter(Function.$true, '').__extend__);
                    this.is(__extend__, Function.getter(Function.$true, function(){}).__extend__);
                    this.is(__extend__, Function.getter(Function.$true, {}).__extend__);
                    this.is(__extend__, Function.getter(Function.$true, []).__extend__);

                    this.is(__extend__, Function.getter(function(){}).__extend__);
                    this.is(__extend__, Function.getter(function(){}, '').__extend__);
                    this.is(__extend__, Function.getter(function(){}, function(){}).__extend__);
                    this.is(__extend__, Function.getter(function(){}, {}).__extend__);
                    this.is(__extend__, Function.getter(function(){}, []).__extend__);

                    this.is(__extend__, Function.getter(getter).__extend__);
                    this.is(__extend__, Function.getter(getter, '').__extend__);
                    this.is(__extend__, Function.getter(getter, getter).__extend__);
                    this.is(__extend__, Function.getter(getter, {}).__extend__);
                    this.is(__extend__, Function.getter(getter, []).__extend__);

                    this.is(true, Function.getter('a').__extend__() === Function.getter());
                    this.is(true, Function.getter('a').__extend__() === Function.nullGetter);
                    this.is(true, Function.getter('a').__extend__('a') === Function.getter('a'));
                    this.is(true, Function.getter('a').__extend__(func) === Function.getter(func));
                  }
                }
              ]
            }
          ]
        }
      ];

    })());

//    if (top.nextTest)
//      top.nextTest();

  </script>
</body>

</html>